import java.util.HashMap;
import java.util.Scanner;

public class StringTransformation {
    public static boolean canTransform(String str1, String str2) {
        if (str1.length() != str2.length()) {
            return false;
        }

        // 映射 str1 -> str2 和 str2 -> str1
        HashMap<Character, Character> map1 = new HashMap<>();
        HashMap<Character, Character> map2 = new HashMap<>();

        for (int i = 0; i < str1.length(); i++) {
            char c1 = str1.charAt(i);
            char c2 = str2.charAt(i);

            // 检查 str1 -> str2 的映射是否一致
            if (map1.containsKey(c1)) {
                if (map1.get(c1) != c2) {
                    return false;
                }
            } else {
                map1.put(c1, c2);
            }

            // 检查 str2 -> str1 的映射是否一致
            if (map2.containsKey(c2)) {
                if (map2.get(c2) != c1) {
                    return false;
                }
            } else {
                map2.put(c2, c1);
            }
        }

        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.next();
        String str2 = scanner.next();

        boolean result = canTransform(str1, str2);
        System.out.println(result);
    }
}
